package com.len.controller;

import com.len.core.annotation.Log;
import com.len.entity.Dict;
import com.len.exception.MyException;
import com.len.service.LoadsDictService;
import com.len.util.JsonUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author songxiangyang
 * @date 2019/4/3 下午2:31
 * @email songxiangyang@aliyun.com
 */
@Controller
@RequestMapping(value = "/loadsDict")
public class LoadsDictController {

    @Autowired
    private LoadsDictService loadsDictService;

    @ApiOperation(value = "/loadsDictionary", httpMethod = "POST", notes = "查询字典")
    @Log(desc = "查询字典")
    @PostMapping(value = "loadsDictionary")
    @ResponseBody
    public JsonUtil loadsDictionary(Dict dict) {
        JsonUtil j = new JsonUtil();
        try {
            Map<String, String> dictMap = loadsDictService.loadsDictionary(dict);
            j.setData(dictMap);
            j.setMsg("保存成功");
        } catch (MyException e) {
            j.setMsg("保存失败");
            j.setFlag(false);
            e.printStackTrace();
        }
        return j;
    }

    @ApiOperation(value = "/selectDictList", httpMethod = "GET", notes = "展示字典")
    @GetMapping(value = "selectDictList")
    @ResponseBody
    public JsonUtil selectDictList(Dict dict) {
        return loadsDictService.selectDictList(dict);
    }
}
